<include file="public@meta" />

<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- table顶部工具栏结束 -->

            <!-- table表格开始 -->
            <table id="layer-table-list" lay-filter="layer-table-list"></table>
            <!-- table表格结束 -->
            <script type="text/html" id="toolbarTpl">
                <div class="layui-btn-group">
                    <button class="layui-btn layuiadmin-btn-list layui-btn-sm" lay-event="add"><i class="layui-icon">&#xe608;</i>添加幻灯片</button>
                </div>
            </script>
            <!-- table右侧工具栏开始 -->
            <script type="text/html" id="barLists">
                <a class="layui-btn layui-btn-xs layui-btn-normal" href="{:url('items')}?slideID={{d.id}}">
                    <i class="layui-icon layui-icon-edit"></i>图片管理</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete"><i
                        class="layui-icon layui-icon-delete"></i>删除</a>
            </script>
            <!-- table右侧工具栏结束 -->
            <!-- table状态栏开始 -->
            <script type="text/html" id="toolbar-status">
                {{#  if(d.status == 1){ }}
                <input lay-filter="status-list-id" type="checkbox" value="{{ d.id }}" name="status-list-id" lay-skin="switch" lay-text="正常|禁用" checked>
                {{#  } else { }}
                <input lay-filter="status-list-id" type="checkbox" value="{{ d.id }}" name="status-list-id" lay-skin="switch" lay-text="正常|禁用">
                {{#  } }}
            </script>
            <!-- table状态栏结束 -->
        </div>
    </div>
</div>
<script>
    layui.config({
        base: '__STATIC__/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index', //主入口模块
        layCenter: 'lib/layCenter' //主入口模块
    }).use(['index', 'laydate','form','table','layCenter'], function(){
        var $ = layui.$,
            form = layui.form,
            table = layui.table,
            laydate = layui.laydate,
            layCenter = layui.layCenter;
        // 渲染列表
        table.render({
            elem: '#layer-table-list',
            even: true,
            toolbar: "#toolbarTpl",
            url: "{:url('getRows')}",
            cols: [
                [
                    {field: 'id', title: 'ID', align: 'center', width: 50},
                    {field: 'name', title: '名称', width: 180, edit: 'text', align: 'center'},
                    {field: 'idname', title: '标识', width: 180, align: 'center'},
                    {field: 'remark', title: '备注', edit: 'text'},
                    {title: '操作', width: 200, align: 'center', toolbar: '#barLists'}
                ]
            ]
        });


        //监听搜索
        form.on('submit(layer-table-list-search)', function(data){
            var field = data.field;
            console.log(field);
            //执行重载
            table.reload('layer-table-list', {
                where: field
            });
        });

        //用户状态的修改
        form.on('switch(status-list-id)', function(data){
            var status = this.checked ? '1' : '2';
            //请求接口修改状态
            var url = "{:url('updateStatus')}";
            layCenter.Ajax(url,{id:data.value,status:status})
        });

        // 头部工具监听事件
        table.on('toolbar(layer-table-list)', function(obj){
            switch(obj.event){
                case 'add':
                    layCenter.CreateOpenForm('添加新管理员',"{:url('add')}","600px","600px");
                    break;
            };
        });

        // 工具条监听事件
        table.on('tool(layer-table-list)',function(obj){
            var data = obj.data; //获得当前行数据
            switch(obj.event){
                case 'delete':
                    // 删除
                    layCenter.DelByIds("{:url('delAdmin')}",data.id);
                    break;
            }
        });


    });
</script>
</body>
</html>